const zlib = require('zlib');
const fs = require('fs');
const path = require('path');

// 压缩文件为gz格式
// 创建一个读取流
// let readStream = fs.createReadStream(path.resolve(__dirname, 'test.txt'));
// // 创建一个写入流
// let writeStream = fs.createWriteStream(path.resolve(__dirname, 'test.txt.gz'));
// // 使用zlib进行压缩
// readStream.pipe(zlib.createGzip()).pipe(writeStream);

// 解压gz文件
// 创建一个读取流
let readStream2 = fs.createReadStream(path.resolve(__dirname, 'test.txt.gz'));
// 创建一个写入流
let writeStream2 = fs.createWriteStream(path.resolve(__dirname, 'test2.txt'));
// 使用zlib进行解压
readStream2.pipe(zlib.createGunzip()).pipe(writeStream2);